import { diff } from "./diff"

export function updateComponent (vdom, oldComponent, oldDom, container) {
  oldComponent.componentWillReceiveProps(vdom.props)
  if (oldComponent.shouldComponentUpdate(vdom.props)) {
    // 未更前前的props
    let prevProps = oldComponent.props
    oldComponent.componentWillUpdate(vdom.props)

    /* 
    组件更新：
    1. 更新props
    2. 同步更新vdom的component对向
    */
    // 1
    oldComponent.updateProps(vdom.props)
    let nextVdom = oldComponent.render()
    // 2
    nextVdom.component = oldComponent
    diff(nextVdom, container, oldDom)


    oldComponent.componentDidUpdate(prevProps)
  }
}